load motor.mat;
XtestNorm = motorNormalize(Xtest);
XtrainNorm = motorNormalize(Xtrain);

X = linspace(-1, 1);
X = X';

meanPredictionsPoly = zeros(100,1);

numDataPoints = size(XtrainNorm,1);
for Mindex=100:100
    powerIndex = Mindex;
    designMatrix = ones(numDataPoints,powerIndex+1);
    for rowDesign=1:numDataPoints
        for colDesign=2:powerIndex+1
            designMatrix(rowDesign,colDesign)=XtrainNorm(rowDesign,1).^(colDesign-1);
        end
    end
    w = (designMatrix' * designMatrix* (400*0.00453487850812858*eye(Mindex+1)))\designMatrix' * Ytrain;
    w %dump out w value
    
    YPredict = zeros(size(X,1),1);
    for xtestIndex=1:size(X,1)
        YPredict(xtestIndex,1) =  w(1,1);
        for xPower=2:powerIndex+1
            YPredict(xtestIndex,1) = YPredict(xtestIndex,1) + X(xtestIndex,1).^(xPower-1)*w(xPower,1);
        end
    end
    figure(261)
    plot(X, YPredict)
    %polynomialFor100 = sum(YPredict)/size(XtestNorm,1) %dump out value

end

meanPredictionsRadial = zeros(100,1);

numDataPoints = size(XtrainNorm,1);
for Mindex=100:100
    
    mu = linspace(-1,1,Mindex);
    sigma = 3*(mu(2)-mu(1));
    
    designMatrix = ones(numDataPoints,powerIndex+1);
    for rowDesign=1:numDataPoints
        for colDesign=2:powerIndex+1
            designMatrix(rowDesign,colDesign)=exp(-(XtrainNorm(rowDesign,1)-mu(colDesign-1))^2 / 2*sigma^2);
        end
    end
    w = (designMatrix' * designMatrix* (400*0.00453487850812858*eye(Mindex+1)))\designMatrix' * Ytrain;
    w %dump out w value

    testPhi = ones(size(X,1),Mindex+1);
    for x=1:size(X,1)
        for j = 2:Mindex+1
            testPhi(x,j) = exp(-(X(x)-mu(j-1))^2 / 2*sigma^2);
        end
    end
    
    
    YPredict = zeros(size(X,1),1);
    for xtestIndex=1:size(X,1)
        YPredict(xtestIndex,1) = testPhi(xtestIndex,:)*w;
    end
    figure(262)
    plot(X, YPredict)
    %radialFor100 = sum(YPredict)/size(XtestNorm,1) %dump out value

end

%alpha = 0.00259502421139974
%alpha = 1

%alpha = 0.00259502421139974
%alpha = 0.00453487850812858

